package org.twb.o2o.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.twb.o2o.dao.UserDao;
import org.twb.o2o.domain.User;
import org.twb.o2o.service.UserService;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by km on 2017/4/20.
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User findById(Long id) {
      return userDao.findById(id);
    }

    @Override
    public List<User> findAll() {
      return userDao.findAll();
    }

    @Override
    public void delete(Long id) {
        userDao.delete(id);
    }

    @Override
    public void saveUser(User user) {
        userDao.saveUser(user);
    }

    @Override
    public List<User> findAllByCondition(String userName) {
        return userDao.findAll().stream().filter(x->x.getUserName()
                .equalsIgnoreCase(userName))
                .collect(Collectors.toList());
    }
}
